package com.nuo.modules.question.controller;

import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import com.nuo.modules.question.po.AddQuestionPo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.nuo.modules.question.entity.QuestionEntity;
import com.nuo.modules.question.service.QuestionService;
import com.nuo.common.utils.PageUtils;
import com.nuo.common.utils.R;



/**
 * 
 *
 * @author nuo
 * @email 3033616351@qq.com
 * @date 2022-11-04 16:45:13
 */
@RestController
@RequestMapping("question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    /**
     * 前台学生提问
     */
    @PostMapping("/add")
    public R add(@RequestBody AddQuestionPo po){
        return questionService.add(po);
    }

    /**
     * 前台学生获取自己的问题列表
     */
    @PostMapping("/getList")
    public R getList(@RequestBody Map<String, Object> params){
        return questionService.getList(params);

    }

    /**
     * 列表
     */
    @RequestMapping("/list")
        public R list(@RequestParam Map<String, Object> params){
        PageUtils page = questionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
        public R info(@PathVariable("id") Long id){
		QuestionEntity question = questionService.getById(id);

        return R.ok().put("question", question);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        public R save(@RequestBody QuestionEntity question){
		questionService.save(question);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        public R update(@RequestBody QuestionEntity question){
		questionService.updateById(question);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        public R delete(@RequestBody Long[] ids){
		questionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
